package com.wx;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.Set;

/**
 * @User: Jrxsr
 * Filter
 * on 2019/1/2.
 **/
@WebFilter(filterName = "FilterThread", urlPatterns = "/*")
public class WxFilter implements Filter {
    class Sleep implements Runnable{
        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Thread thread = new Thread(Setinterval.getInstance());
            thread.start();
        }
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("wx初始化");
        Setinterval.getInstance().setUrl("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxfccb1821cfcead08&secret=8380e975dab4314c0704ed71b172616e");
        Thread thread = new Thread(new Sleep());
        thread.start();

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
